<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>党员卡管理管理</title>
	<meta name="decorator" content="default"/>
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/layout.css">
	<script src="<%=request.getContextPath()%>/static/layer/layer.js"></script>
	<script type="text/javascript">
	
		$(document).ready(function() {
			//打开打卡机
			$('#openCard').click(function (){
				
				 var str=window.navigator.userAgent.toLowerCase();
				 if(str.indexOf('chrome')!=-1){
		    		  
		          }else if(str.indexOf('msie')!=-1){  
		        	  top.saveCardWin();
		          }
				var personid = $("#personid").val();
				var hashnumber = $("#hashnumber").val();
				var cardnumber = $("#cardnumber").val();
				var personname = $("#personname").val();
				
			});
			
			//切换成只读模式
			$('#chageMode').click(function(){
				top.changeMode();
			});
			
			//写卡
             $('#xk').click(function (){	
            	var personid = $("#personid").val();
 				var hashnumber = $("#hashnumber").val();
 				var cn = $("#cardnumber").val();
 				var cardnumber = "CY"+$("#cardnumber").val();
 				var personname = $("#personname").val();
 				var column3 = $("#column3").find("option:selected").val();
 				
 				if(personid==null || personid==''){
					alert("请选择党员!");
				}else if(personname==null || personname==''){
					alert("请选择党员!");
				}else if(cn ==null || cn==''){
					alert("请输入要绑定的卡号!");
				}else{
            	 $.ajax({
						url:"${ctx}/partycard/partycard/getCardNum",
						type:"GET",
						dataType:"json",
						data:{
							"personid":personid,
							"hashnumber":hashnumber,
							"cardnumber":cardnumber,
							"personname":personname,
							"column3":column3
						},
						success:function(data){
							var msg = data.msg;
							var code = data.code;
							if(code=="100"){
								alert(msg);
							}else if(code=="400"){
								alert(msg);
							}else{
								var check=top.writeCard();
								 if(check){
									 $.ajax({
											url:"${ctx}/partycard/partycard/save",
											type:"post",
											dataType:"json",
											data:{
												"personid":personid,
												"hashnumber":hashnumber,
												"cardnumber":cardnumber,
												"personname":personname,
												"column3":column3
											},
											success:function(data){
												var msg = data.msg;
												var code = data.code;
												
												alert(msg);
											//	window.location.href = "${ctx}/partycard/partycard/form";
											}
										}); 
								    }							
							}													
						}
					});         	 
				}
			});
			
			
// 			$("#inputForm").validate({
// 				submitHandler: function(form){
// 					loading('正在提交，请稍等...');
// 					form.submit();
// 				},
// 				errorContainer: "#messageBox",
// 				errorPlacement: function(error, element) {
// 					$("#messageBox").text("输入有误，请先更正。");
// 					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
// 						error.appendTo(element.parent().parent());
// 					} else {
// 						error.insertAfter(element);
// 					}
// 				}
// 			});
		});
		function fun(){
			$("#personname").val($(".sds:checked").parent().parent().children("td" ).eq(1).text());
			$("#personid").val($("input[name='radioPersonId']:checked").val());
			$("#hashnumber").val($(".sds:checked").parent().parent().children("td" ).eq(2).children("input").eq(0).val());			
		}
		
	    //创建签到总的对象
		function createDk() {
			var object = new Object();
			object.id = id;
			return object;
	    }
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/partycard/partycard/">党员卡管理列表</a></li>
		<li class="active"><a href="${ctx}/partycard/partycard/form?id=${partycard.id}">党员卡管理<shiro:hasPermission name="partycard:partycard:edit">${not empty partycard.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="partycard:partycard:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
<div style="width:20%;height:500px;float:left;">

</div>
<div class='tab-pane' style="width:20%;height:600px;float:left;">

<%-- <div style="overflow-y:scroll; height:600px;">
<c:forEach var="d" items="${list}" varStatus="i">	
<ul>
  <tr id='${ i.index}'>
					<td  style='width:30px'><input type='radio' class='sds' onclick="fun()" id='radioPersonId' name='radioPersonId' value="${d.userId }"></td>
					<td style='width:100px'><span style='color:black'></span>${d.userName }</td>
					<td style='width:50px'><span style='color:black'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${d.sex }					
					<input type="hidden"  id="a" value="${d.hashnumber }" ></input>
					</td>
</tr>
</ul>
</c:forEach>
</div> --%>

<div style="overflow-y:scroll; height:550px;">
<table>
<c:forEach var="d" items="${list}" varStatus="i">		
<tr id='${ i.index}'>
					<td  style='width:30px'><input type='radio' class='sds' onclick="fun()" id='radioPersonId' name='radioPersonId' value="${d.userId }"></td>
					<td style='width:100px'><span style='color:black'></span>${d.userName }</td>
					<td style='width:50px'><span style='color:black'></span>${d.sex }					
					<input type="hidden"  id="a" value="${d.hashnumber }" ></input>
					</td>

</tr>
</c:forEach>
</table>
</div>


</div>

<div style="width:40%;height:500px;float:left;border:1px solid #000">
<hr>
<hr>
<form:form id="inputForm" modelAttribute="partycard" action="${ctx}/partycard/partycard/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		
		<div class="control-group">
			<label class="control-label">党员卡卡号：</label>
			<div class="controls">
				<form:input path="cardnumber" style="width:200px" htmlEscape="false" maxlength="32" class="input-medium  required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">党员姓名：</label>
			<div class="controls">
				<form:input path="personname" style="width:100px" readonly="true" htmlEscape="false" maxlength="30" class="input-medium  required"/>
				<form:hidden path="personid"/>
				<form:hidden path="hashnumber"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否纳入积分考核：</label>
			<div class="controls">
				<select id="column3" name="column3" style="width:100px"> 
				<option value ="1" selected="selected">是</option>
				<option value ="2">否</option>
				</select> 
			</div>
		</div>
		<div class="form-actions">
			<button class="btn" id="openCard"  data-toggle="modal" data-target="#modal-del">写卡模式开启</button>
			<button class="btn" id="chageMode"  data-toggle="modal" data-target="#modal-del">读卡模式开启</button>
			<button class="btn" id="xk"  data-toggle="modal" data-target="#modal-del">写卡</button>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
			
		</div>	
1 请下载控件<a href="${ctxStatic}/cj/cj.zip">控件下载</a> ，安装成功后，请重新打开浏览器，右上角无提示“控件不可用，可能未正确安装控件及驱动，或者控件未启用。”，表示安装成功。<br>
2 请先点击“打开读卡器”，读卡成功后，放入党员卡。<br>
3 左侧选择党员，请核对党员卡，并把卡片中卡号填写到党员卡卡号区，点击“写卡”。<br>
4 写卡成功后，请检测卡片是否写卡成功。
	</form:form>
</div>	
</body>
</html>